/**
 * Created by dqw on 2015/12/30.
 */
//列表开始
var dtGridColumns = [
    {
        id: 'delFlag',
        type: 'int',
        hideQuery:true,
        'export':false,
        hideQueryType:'eq',
        hideQueryValue:1,
        hide:true
    },
    {
        id: 'id',
        title: 'ID',
        type: 'number',
        columnClass: 'text-center width-100',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'eq'
    },
    {
        id: 'b.userName',
        title: '用户姓名',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center width-200',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'b.mobilePhone',
        title: '用户手机',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'total',
        title: '账户总额',
        type: 'number',
        headerClass: 'text-center',
        columnClass: 'text-right',
        fastSort: false,
        fastQuery: false,
        format:'#,##0.00',
        fastQueryType: 'range'
    },
    {
        id: 'available',
        title: '可用金额',
        type: 'number',
        headerClass: 'text-center',
        columnClass: 'text-right',
        fastSort: false,
        fastQuery: false,
        format:'#,##0.00',
        fastQueryType: 'range'
    },
    {
        id: 'freeze',
        title: '冻结金额',
        type: 'number',
        headerClass: 'text-center',
        columnClass: 'text-right',
        fastSort: false,
        fastQuery: false,
        format:'#,##0.00',
        fastQueryType: 'range'
    },
    {
        id: 'tenderCount',
        title: '点买总额',
        type: 'number',
        headerClass: 'text-center',
        columnClass: 'text-right',
        fastSort: false,
        fastQuery: false,
        format:'#,##0.00',
        fastQueryType: 'range'
    },
    // {
    //     id: 'feeCount',
    //     title: '费用总额',
    //     type: 'number',
    //     headerClass: 'text-center',
    //     columnClass: 'text-right',
    //     fastSort: true,
    //     fastQuery: true,
    //     format:'#,##0.00',
    //     fastQueryType: 'range'
    // },
    {
        id: 'profitCount',
        title: '盈利总额',
        type: 'number',
        headerClass: 'text-center',
        columnClass: 'text-right',
        fastSort: false,
        fastQuery: false,
        // format:'#,##0.00',
        fastQueryType: 'range'
    },
    {
        id: 'operation',
        title: '资金修改',
        type: 'string',
        columnClass: 'text-center width-200',
        fastSort: false,
        extra: false,
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var edit;
            if($("#editPermi") && $("#editPermi").val() == 1 ){
                edit = "<a data-target='#editModal' class='btn btn-sm btn-primary m-r-10' data-toggle='modal' data-no='" + dataNo + "' ><i class='fa fa-edit'></i>&nbsp;资金修改&nbsp;</a>";
            }
            return edit;
        }
    }
];

var dtGridOption = {
    lang: 'zh-cn',
    ajaxLoad: true,
    loadURL: ncGlobal.adminRoot + 'simulation/account/json/list',
    exportFileName: '模拟账户列表',
    columns: dtGridColumns,
    gridContainer: 'dtGridContainer',
    toolbarContainer: 'dtGridToolBarContainer',
    pageSize: 10,
    pageSizeLimit: [10, 20, 50],
    ncColumnsType: {int:["id"],String :["b.userName","b.mobilePhone"]}
};

var grid = $.fn.DtGrid.init(dtGridOption);
grid.fastQueryParameters =new Object();

//排序
grid.sortParameter.columnId = 'asc_id';
grid.fastQueryParameters['eq_delFlag'] = 1;
grid.sortParameter.sortType = 1;
//列表结束

//操作处理开始
var OperateHandle = function () {

    function _bindEvent() {

        //新增对话框初始化
        $("#addModal").on("show.bs.modal", function (event) {
            //清除错误信息
            $(".alert-danger").remove();
            $("#addForm").psly().reset();

            $("#addForm").find("[name='name']").val("");
            $("#addForm").find("[name='password']").val("");
            $("#addForm").find("[name='password2']").val("");
            $("#addForm").find("[name='id']").val("");
        });

        $('#editModal').on('show.bs.modal', function (event) {
            var    //获取接受事件的元素
            button = $(event.relatedTarget),
            //获取data 参数
            datano = button.data('no'),
            modal = $(this),
            //获取列表框中的原始数据
            gridData = grid.sortOriginalDatas[datano],
            editForm = $("#editForm");
            //清除错误提示
            editForm.psly().reset();
            $(".alert-danger").remove();
            modal.find('input[name="id"]').val(gridData.id);
            modal.find('input[name="userId"]').val(gridData.userId);
            modal.find('input[name="userName"]').val(gridData.b.userName);
            modal.find('input[name="id"]').val(gridData.id);
            $("#editForm").find("[name='accountNum']").val("");
        });
        //模糊搜索
        $('#customSearch').click(function () {
            grid.fastQueryParameters = new Object();
            grid.fastQueryParameters['lk_b.user_name_or_like_b.mobile_phone'] = $('#keyword').val();
            grid.pager.startRecord = 0;
            grid.pager.nowPage = 1;
            grid.pager.recordCount = -1;
            grid.pager.pageCount = -1;
            grid.refresh(true);
        });
    }

    //外部可调用
    return {
        bindEvent: _bindEvent
    }
}();
//操作处理结束

$(function () {
    //加载列表
    grid.load();
    //页面绑定事件
    OperateHandle.bindEvent();
});